<?php

namespace yiike\credit\models\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yiike\credit\models\Credit;

/**
* CreditSearch represents the model behind the search form about `yiike\credit\models\Credit`.
*/
class CreditSearch extends Credit
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'value1', 'value2', 'value3'], 'integer'],
            [['value1_encrypt', 'value2_encrypt', 'value3_encrypt', 'password'], 'safe'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Credit::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'user_id' => $this->user_id,
            'value1' => $this->value1,
            'value2' => $this->value2,
            'value3' => $this->value3,
        ]);

        $query->andFilterWhere(['like', 'value1_encrypt', $this->value1_encrypt])
            ->andFilterWhere(['like', 'value2_encrypt', $this->value2_encrypt])
            ->andFilterWhere(['like', 'value3_encrypt', $this->value3_encrypt])
            ->andFilterWhere(['like', 'password', $this->password]);

return $dataProvider;
}
}